<?php

require_once "./core/template.php";

echo getHeader("Versions!");

?>

<p>
	<form class="form-install">
		<label for="login">Login: </label> <input type="text" name="login" class="input" id="login" /><br />					
		<label for="password">Password: </label> <input type="password" name="pwd" class="input" id="password" /><br />
		<label>&nbsp; </label> <input type="button" value="Submit" onClick="checkLog()"/>
		<div class="warning" id="warning">Wrong login/password</div>					
	</form>
	
</p>
<script language="javascript">
function checkLog() {
	
	$.ajax({
		url: 'checkLog.php',
		type: "POST",
		data: {login: $("#login").val(), password: $("#password").val()},
		success: function(data) {
			var response = jQuery.parseJSON(data);
				
			if (response.error == 0){
				document.location.reload();
			}
			else if (response.error == 3){
				console.log("wrong login/pwd");
				$("#warning").css('display', 'block');
			}
			else {
				console.log('Insertion failed, reason: ' + response.message);
			}

		},
		error: function (jqXHR) {
			console.log("call failed " + jqXHR);
		}

	});
	
}
</script>

<?php
	echo getFooter();
?>
